<?php
defined ( 'IN_TS' ) or die ( 'Access Denied.' );

$userid = intval ( $TS_USER ['userid'] );

$strUser = aac('user')->getOneUser($userid);



$topicid = intval ( $_POST ['topicid'] );


$isRecommend = $new ['group']->findCount ( 'group_topic_recommend', array (
		'topicid' => $topicid,
		'userid' => $userid 
) );

$strTopic = $new ['group']->find('group_topic',array(
	'topicid'=>$topicid,
));

if ($isRecommend > 0) {
	$isRecommend = $new ['group']->delete ( 'group_topic_recommend', array (
		'topicid' => $topicid,
		'userid' => $userid
	) );
	// 对积分进行处理
	aac('user') -> doScore($TS_URL['app'], $TS_URL['ac'], $TS_URL['ts'],$strTopic['userid'],-5);
	aac('user') -> doScore($TS_URL['app'], $TS_URL['ac'], $TS_URL['ts'],$userid,5);

}else{


	if ($strUser['count_score']<5) {
		echo 0;
		exit ();
	}

	$new ['group']->create ( 'group_topic_recommend', array (
		'topicid' => $topicid,
		'userid' => $userid
	) );

	// 对积分进行处理
	aac('user') -> doScore($TS_URL['app'], $TS_URL['ac'], $TS_URL['ts'],$strTopic['userid'],5);
	aac('user') -> doScore($TS_URL['app'], $TS_URL['ac'], $TS_URL['ts'],$userid,-5);

}


$count_recommend = $new ['group']->findCount ( 'group_topic_recommend', array (
		'topicid' => $topicid 
) );

$new ['group']->update ( 'group_topic', array (
		'topicid' => $topicid 
), array (
		'count_recommend' => $count_recommend 
) );

echo 1;
exit ();